package com.wm.blog_admin.controller;

import com.wm.blog_admin.controller.base.AdminBaseController;
import com.wm.blog_admin.service.UploadService;
import com.wm.blog_common.req.TFileQuery;
import com.wm.blog_common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 上传接口
 * @author 半卷流年
 * @date 2020-5-9 16:18
 */
@RestController
@RequestMapping("/blog/upload")
@Slf4j
public class UploadController extends AdminBaseController {

    @Autowired
    private UploadService uploadService;

    /**
     * 上传图片
     */
    @PostMapping(value = "/uploadPicture",produces = "application/json; charset=utf-8")
   public Result<String> uploadPicture(MultipartFile file,HttpServletRequest request){
        TFileQuery query = new TFileQuery();
        query.setAdminId(super.currentAdminId(request));
        return uploadService.uploadPicture(query,file);
   }
}
